package Complex;

class Complex
{
    int realPart;
    int imaginPart;
    Complex()
    {
        realPart = 0;
        imaginPart = 0;
    }
    Complex(int r,int i)
    {
        realPart = r;
        imaginPart = i;
    }
    Complex complexAdd(Complex a)
    {
        Complex tmp = new Complex();
        tmp.realPart = realPart + a.realPart;
        tmp.imaginPart = imaginPart + a.imaginPart;
        return tmp;
    }
    public String toString()
    {
        if(realPart == 0 && imaginPart != 0)
        {
            return imaginPart+"i";
        }
        else if(imaginPart == 0)
        {
            return String.valueOf(realPart);
        }
        else
        {
            return realPart+"+"+imaginPart+"i";
        }
    }
}
public class Test {
    public static void main(String[] args)
    {
        Complex a = new Complex(1,2);
        Complex b = new Complex(1,-2);
        Complex c = new Complex(3,4);
        Complex d = new Complex(-1,2);
        Complex e = a.complexAdd(b);
        Complex f = a.complexAdd(c);
        Complex g = a.complexAdd(d);
        System.out.println(e.toString());
        System.out.println(f.toString());
        System.out.println(g.toString());
    }
}
